#include <REGX52.H>
#include "timer0.h"

sbit ENA=P0^1;
sbit ENB=P0^6;
sbit IN1=P0^2;
sbit IN2=P0^3;
sbit IN3=P0^4;
sbit IN4=P0^5;



#define go_straight 1;
#define back_off 2;
#define turn_lift 3;
#define turn_right 4;
#define stop 0;

unsigned int timer_101;
	

int flag;
unsigned char left,right;
unsigned char pwma,pwmb;

void PWM() interrupt 1
{
	TL0 = 0xF7;				//设置定时初始值
	TH0 = 0xFF;				//设置定时初始值
	left++;
	right++;
	
	left %= 100;
	right %= 100;
	
	if(left <= pwma)
	{ 
		ENA = 1;
	}
	else
		{
			ENA = 0;
		}

	if(right <= pwmb)
		{ 
			ENB = 1;
		}
	else
		{
			ENB = 0;
		}
	
	timer_101++;
		
		
//	if(P2_3==0)
//		{
//			flag=1;
//		}	
//		
//	if(P2_3==1)
//		{
//			flag=0;
//		}	

		
}

void car_doing_1(int direction, int speed_right, int speed_lift)
{
		if (direction == 0)
		{
					IN1 = 0;
					IN2 = 0;
					pwma = speed_lift;
					IN3 = 0;
					IN4 = 0;
					pwmb = speed_right;
		}
			
    if (direction == 1)
		{
					IN1 = 1;
					IN2 = 0;
					pwma = speed_lift;
					IN3 = 1;
					IN4 = 0;
					pwmb = speed_right;
		}
			
		if (direction == 2)
		{
					IN1 = 0;
					IN2 = 1;
					pwma = speed_lift;
					IN3 = 0;
					IN4 =1;
					pwmb = speed_right;
		}
		

		if	(direction == 3)
		{
				IN1 = 1;
				IN2 = 0;
				pwma = speed_lift;
				IN3 = 0;
				IN4 = 1;
				pwmb = speed_right;
			
		}

		if	(direction == 4)
		{
				IN1 = 0;
				IN2 = 1;
				pwma = speed_lift;
				IN3 = 1;
				IN4 = 0;
				pwmb = speed_right;
			
		}
}


//void bizhang()
//{
//		if(flag==1)
//			{
//				car_doing_1(1,50,50);
//			}
//		if(flag==0)
//			{
//				car_doing_1(3,50,50);

//			}
//}








